<template>
  <el-form :model="data">
    <el-form-item ref="searchRef" prop="username" :label="label"
      ><el-input v-model="data.username" :placeholder="placeholder"></el-input>
      <el-button @click="resetField">清空</el-button>
      <el-button type="primary" class="search" @click="search">搜索</el-button>
      <el-button type="success" class="editBtn">
        <i class="el-icon-edit" @click="add">{{ btnName }}</i></el-button
      >
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  name: 'elform',
  props: {
    btnName: {
      type: String,
      required: true
    },
    placeholder: {
      type: String,
      required: true
    },
    label: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      data: {
        username: null
      }
    }
  },
  created() {},
  methods: {
    resetField() {
      this.$refs.searchRef.resetField()
    },
    search() {
      this.$emit('search', this.data.username)
    },
    add() {
      this.$emit('add')
    }
  }
}
</script>

<style scoped lang="scss">
.el-form .el-form-item {
  margin-bottom: 18px;
  .el-input {
    width: 200px;
    position: relative;
    display: inline-block;
    height: 32px;
    line-height: 32px;
  }
  .el-button {
    margin-left: 15px;
    padding: 9px 15px;
    border-radius: 3px;
  }
  .search {
    margin-left: 10px;
  }
  .editBtn {
    margin-left: 10px;
    float: right;
    padding: 9px 15px;
    border-radius: 3px;
  }
}
</style>
